import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { BasicFetchResult } from './model/baseModel';

import { CreateAppConnectionParams, AppConnectionModel, GetAppConnectionListParams, ActiveAppConnectionParams } from './model/appConnection';
import { CreateCertificateParams } from './model/certificate';


export function getAppConnectionList(params: GetAppConnectionListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<AppConnectionModel>>(
    {
      url: '/connection/app-connections',
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

export function createAppConnection(params: CreateAppConnectionParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<AppConnectionModel>(
    {
      url: '/connection/app-connections',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function activeAppConnection(id: number, params: ActiveAppConnectionParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: `/connection/app-connections/${id}/active`,
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function generateAppCertificate(id: number, params: CreateCertificateParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: `/connection/app-connections/${id}/certificates/generate`,
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}
